//
// Created by liushuai on 2020/2/11.
//

#include "reverse.h"

int reverse(int x) {
<<<<<<< HEAD:cxx/algorithm/src/reverse.cc
    int result = 0;
    while (x != 0) {
        int b = x % 10;
        x /= 10;
        if (result > INT_MAX / 10 || (result == INT_MAX / 10 && b > INT_MAX%10)) return 0;
        if (result < INT_MIN / 10 || (result == INT_MIN / 10 && b < INT_MIN%10)) return 0;
        result = result * 10 + b;
    }
    return result;

=======
  int result = 0;
  while (x != 0) {
    int b = x % 10;
    x /= 10;
    if (result > INT_MAX / 10 || (result == INT_MAX / 10 && b > INT_MAX % 10))
      return 0;
    if (result < INT_MIN / 10 || (result == INT_MIN / 10 && b < INT_MIN % 10))
      return 0;
    result = result * 10 + b;
  }
  return result;
>>>>>>> dev:cxx/algorithm/common/src/reverse.cc
}